Servo motor with a ultrasonic sensor

I have a servo and ultrasonic sensor and want to map the ultrasonic cm readings to the servo motor. currently the ultrasonic reads on the serial monitor but the servo motor doesn't respond and only twitches and only goes a few degrees and stops. I'm fairly new to coding and everything so sorry in advanced for the sloppy coding.

#include <Servo.h>
int trig = 6;
int echo = A0;
int servo = 9;
Servo myServo;
float duration_us, distance_cm;

void setup() {
  Serial.begin(9600);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  myServo.attach(9); 
  myServo.write(0);
}

void loop(){
  distance_cm = analogRead(A0);
  duration_us = map(distance_cm, 0, 1023, 0, 255);
  myServo.write(distance_cm);
  digitalWrite(trig,  HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration_us = pulseIn(echo, HIGH);
  distance_cm = 0.017 * duration_us;
  Serial.print("distance");
  Serial.print(distance_cm);
  Serial.println("cm");

  delay(500);
}